<template>
  <div class="app-container pagebox">
    <a-button class="button" type="primary" @click="bulkedit">
      批量修改
    </a-button>
    <div class="bg">
      <div style="background-color: #fff">
        <a-table
          :pagination="false"
          :columns="columns"
          :data-source="data"
          :rowKey="
            (record, index) => {
              return index;
            }
          "
        >
        <template slot="produceTime" slot-scope="text">
          {{text|formatSeconds}}
        </template>
          <template slot="operAte" slot-scope="text, record, index">
            <!-- <a-popconfirm @confirm="() => onDelete(index)"> -->
            <!-- <a-button>编辑</a-button> -->
            <a @click="enitroutine(record, index)">编辑</a>
            <!-- </a-popconfirm> -->
          </template>
        </a-table>
        <EditDialog
          :openDialog.sync="edDialog"
          title="编辑"
          :formData="editFormData"
          @closeDialogRefreshData="refreshFirstDepartment"
        ></EditDialog>
        <BulkEditing
          v-if="bulkeddilog"
          :bulkDialog.sync="bulkeddilog"
          title="批量修改"
          @closeDialogRefreshData="refreshFirstDepartment"
        ></BulkEditing>
      </div>
      <div style="padding: 20px">
        <a-pagination
          size="small"
          :total="total"
          :show-total="(total) => `一共 ${total} 条`"
          :default-page-size="10"
          @change="changepageSignIn"
        />
      </div>
    </div>
  </div>
</template>
<script>
//
import api from '@/api/equipment';
import EditDialog from './component/editdialog';
import BulkEditing from './component/bulkediting';
import Moment from 'moment';

const columns = [
  {
    title: '程序名',
    dataIndex: 'produceName',
  },
  {
    title: '加工机床',
    dataIndex: 'macNumb',
  },
  {
    title: '加工开始时间',
    dataIndex: 'startTime',
  },
  {
    title: '加工结束时间',
    dataIndex: 'endTime',
  },
  {
    title: '加工时间',
    dataIndex: 'produceTime',
    scopedSlots:{customRender:'produceTime'}
  },
  // {
  //   title: '主轴运行时长',
  //   dataIndex: 'spindleTime',
  // },
  // {
  //   title: '主轴最大负载',
  //   dataIndex: 'maxLoad',
  // },
  // {
  //   title: '平均修调',
  //   dataIndex: 'override',
  // },
  {
    title: '当前计件数',
    dataIndex: 'partCount',
  },
  {
    title: '操作',
    dataIndex: 'operAte',
    ellipsis: true,
    scopedSlots: { customRender: 'operAte' },
  },
];

export default {
  name: '',
  components: {
    EditDialog,
    BulkEditing,
  },
  data() {
    return {
      data: [],
      columns,
      form: { num: 1 },
      options1: [],
      options2: [],
      CompanyId: null,
      equList: [],
      equID: null,
      equindex: 0,
      MacSNsList: [],
      editFormData: {},
      MacSNId: null,
      username: null,
      MacSNs: [],
      pageSize: 10,
      pageNum: 1,
      total: 0,
      openDialog: false,
      edDialog: false,
      bulkDialog: false,
      bulkeddilog: false,
      bulkadd: false,
      bulks: false,
    };
  },

  created() {
    if (this.$route.query.macsn) {
      this.MacSNId = this.$route.query.macsn;
      this.equID = this.$route.query.groupid;
    }
    let roleId = localStorage.getItem('roleId');
    if (roleId == 1) {
      this.CompanyId = localStorage.getItem('compid');
    } else {
      this.CompanyId = localStorage.getItem('choseCompanyId');
    }
    this.username = this.userName = localStorage.getItem('userName');
    this.getAllProduce();
  },
  filters: {
    //创建函数名formatSeconds
    formatSeconds(value) {
      let result = parseInt(value);
 
      let y =
        Math.floor(result / 86400) < 10
          ? "0" + Math.floor(result / 86400)
          : Math.floor(result / 86400);
 
      let h =
        Math.floor((result / 3600) % 24) < 10
          ? "0" + Math.floor((result / 3600) % 24)
          : Math.floor((result / 3600) % 24);
 
      let m =
        Math.floor((result / 60) % 60) < 10
          ? "0" + Math.floor((result / 60) % 60)
          : Math.floor((result / 60) % 60);
 
      let s =
        Math.floor(result % 60) < 10
          ? "0" + Math.floor(result % 60)
          : Math.floor(result % 60);
 
      let res = "";
      if (y !== "00") res += `${y}天`;
 
      if (h !== "00") res += `${h}时`;
 
      if (m !== "00") res += `${m}分`;
 
      res += `${s}秒`;
 
      return res;
    },
  },
  methods: {
    changepageSignIn(size) {
      this.pageNum = size;
      this.getAllProduce();
    },
    macSNchange(id) {
      this.pageNum = 1;
      this.MacSNId = id;
      this.getAllProduce();
    },
    changroup(index) {
      this.equID = this.equList[index].groupid;
      this.MacSNs = this.equList[index].MacSNs;
      this.MacSNId = this.MacSNs[0].macsn;
      this.pageNum = 1;
      this.getAllProduce();
    },
    getAllProduce() {
      let params = {
        Username: this.username,
        companyId: this.CompanyId,
        groupId: this.equID,
        macSN: this.MacSNId,
        pageSize: this.pageSize,
        pageNum: this.pageNum,
      };
      api.getAllProduce(params).then((res) => {
        this.data = res.data.rows;
        this.total = res.data.total;
      });
    },
    getEquGroup() {
      let params = {
        Username: this.username,
        compid: this.CompanyId,
      };
      api.CompanyGroupList(params).then((res) => {
        this.equList = res.Data;
        this.equID = this.equList.unshift({ groupname: '全部', groupid: -2 });
        this.equID = this.equList[0].groupid;
        if (this.equList[0].MacSNs) {
          this.MacSNs = this.equList[0].MacSNs;
          this.MacSNId = this.MacSNs[0].macsn;
        }

        this.getAllProduce();
      });
    },
    handleSubmit() {},
    enitroutine(record, index) {
      this.editFormData = Object.assign({}, record); //将数据传入dialog页面
      this.edDialog = true;
    },
    //打开批量按钮
    bulkedit() {
      /*  this.bulktlistData=JSON.parse(JSON.stringify(this.data))
      console.log(this.bulktlistData,'2323'); */
      console.log(123);
      this.bulkeddilog = true;
    },
    refreshFirstDepartment() {
      this.getAllProduce();
    },
  },
};
</script>
<style scoped lang="less">
@import 'index.less';
</style>
